import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Location } from '@angular/common';

import { BookService } from '../../../services/book.service';
import { aroAnimation } from '../../../animation';

@Component({
  selector: 'app-searchlist',
  templateUrl: './searchlist.component.html',
  styleUrls: ['./searchlist.component.css'],
  animations: [aroAnimation]
})
export class SearchlistComponent implements OnInit {

  public keyword: string = '';

  public books: Array<any> = [];

  constructor(private location: Location, private currentRouter: ActivatedRoute, private router: Router,
    private bookService: BookService
  ) { }

  ngOnInit() {
    this.keyword = this.currentRouter.snapshot.params['keyword'];

    this.bookService.getList({ keyword: this.keyword }).subscribe(res => {
      if (res.Code == 100) {
        this.books = res.Data;
        // console.log(this.books);
      }
    });
  }

  public goBack(): void {
    this.location.back();
  }

  public goSearch(): void {
    this.router.navigate(['./search']);
  }

  public goDetail(book): void {
    this.router.navigate(['./bookdetail/', book.Book.Id]);
  }

}
